/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package applety;

import java.awt.Rectangle;
import javax.swing.JApplet;

/**
 *
 * @author Riso-Desktop
 */
public class hra1 extends JApplet {

    mladata v;
    mladata b;
    mladata s;
    mladata m;
    mladata k;
    Rectangle bocianr = new Rectangle(100, 100);
    Rectangle kravar = new Rectangle(100, 100);
    Rectangle sliepkar = new Rectangle(100, 100);
    Rectangle vlkr = new Rectangle(100, 100);
    Rectangle medvedr = new Rectangle(100, 100);
    public static boolean ulozene = false;

    /**
     * Initializes the applet hra1
     */
    private void zaradRect() {
        bocianr.setLocation(bocian.getX() + 1, bocian.getY() + 1);
        kravar.setLocation(krava.getX() + 1, krava.getY() + 1);
        sliepkar.setLocation(sliepka.getX() + 1, sliepka.getY() + 1);
        vlkr.setLocation(vlk.getX(), vlk.getY());
        medvedr.setLocation(medved.getX() + 1, medved.getY() + 1);
    }

    private synchronized void pridajMladata() {
        try {
        
        v = new mladata("/pic/m_vlk.jpg", this);
        b = new mladata("/pic/m_bocian.JPG", this);
        s = new mladata("/pic/m_sliepka.jpg", this);
        m = new mladata("/pic/m_medved.jpg", this);
        k = new mladata("/pic/m_krava.jpg", this);
        mladata[] pole = {v, b, s, m, k};
        for (int i = 0; i < pole.length; i++) {
            this.add(pole[i], 1);
        }
        } catch (Exception e) {
        }
    }

    public void skry() {
        jLabel6.setVisible(false);
    }

    public void vyhodnot() {
        if (m.rect.intersects(medvedr) && v.rect.intersects(vlkr) && b.rect.intersects(bocianr)
                && s.rect.intersects(sliepkar) && k.rect.intersects(kravar)) {
            jLabel6.setVisible(true);
            jLabel6.setText(":-)");
        } else {
            jLabel6.setVisible(true);
            jLabel6.setText(":-(");
        }
    }

    @Override
    public void init() {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(hra1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(hra1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(hra1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(hra1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the applet
         */

        try {
            initComponents();
            this.setSize(550, 380);
            zaradRect();
            jLabel6.setVisible(false);
            pridajMladata();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * This method is called from within the init() method to initialize the
     * form. WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        krava = new javax.swing.JLabel();
        bocian = new javax.swing.JLabel();
        medved = new javax.swing.JLabel();
        sliepka = new javax.swing.JLabel();
        vlk = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(550, 380));
        getContentPane().setLayout(null);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/bocian.jpg"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(22, 24, 100, 100);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/krava.jpg"))); // NOI18N
        getContentPane().add(jLabel2);
        jLabel2.setBounds(128, 24, 100, 100);

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/medved.jpg"))); // NOI18N
        getContentPane().add(jLabel3);
        jLabel3.setBounds(234, 24, 100, 100);

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/sliepka.jpg"))); // NOI18N
        jLabel4.setText("jLabel4");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(340, 24, 100, 100);

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/vlk.jpg"))); // NOI18N
        getContentPane().add(jLabel5);
        jLabel5.setBounds(446, 24, 100, 100);

        krava.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        getContentPane().add(krava);
        krava.setBounds(129, 149, 101, 101);

        bocian.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        getContentPane().add(bocian);
        bocian.setBounds(22, 149, 101, 101);

        medved.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        getContentPane().add(medved);
        medved.setBounds(236, 149, 101, 101);

        sliepka.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        getContentPane().add(sliepka);
        sliepka.setBounds(343, 149, 101, 101);

        vlk.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        getContentPane().add(vlk);
        vlk.setBounds(450, 149, 101, 101);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel6.setText(":-)");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(260, 280, 40, 30);

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel8.setText("Priraď mláďatá k rodičom");
        getContentPane().add(jLabel8);
        jLabel8.setBounds(201, 4, 160, 20);

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/pozadie1.png"))); // NOI18N
        getContentPane().add(jLabel7);
        jLabel7.setBounds(0, 0, 550, 380);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel bocian;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel krava;
    private javax.swing.JLabel medved;
    private javax.swing.JLabel sliepka;
    private javax.swing.JLabel vlk;
    // End of variables declaration//GEN-END:variables
}
